package src.main.StructuralPatterns.Flyweight;

import java.util.HashMap;

// 创建享元工厂
public class CoffeeFactory {
    private static final HashMap<String, Coffee> flavors = new HashMap<>();

    public static Coffee getCoffeeFlavor(String flavorName) {
        Coffee coffee = flavors.get(flavorName);

        if (coffee == null) {
            coffee = new Coffee(flavorName);
            flavors.put(flavorName, coffee);
            System.out.println("Added coffee: " + flavorName);
        }
        return coffee;
    }

    public static int gerTotalFlavor() {
        return flavors.size();
    }
}
